#include "sip_uas.h"
#include "sip_xml.h"

void* UACRegisterRsp(void* sip, UAContext* UContext, UAEncrypt* crypt, int enc_type)
{
	void* rsp = 0;

	if (0 == crypt || *crypt->capability == 0) {
		rsp = UAXMessageRsp(sip, UContext->uac_code, UContext->uac_domain, UContext->uac_ip, UContext->uac_port,
			UContext->uas_code, UContext->uas_domain, UContext->uas_ip, UContext->uas_port, UContext->CSeq, UContext->protocol,401);

		UAXEncAuthenticate(rsp, UContext, crypt,enc_type);
	}
	else {
		if (0 == UAXVerifAuthenticate(sip, UContext, crypt, enc_type)) {
			rsp = UAXMessageRsp(sip, UContext->uac_code, UContext->uac_domain, UContext->uac_ip, UContext->uac_port,
				UContext->uas_code, UContext->uas_domain, UContext->uas_ip, UContext->uas_port, UContext->CSeq, UContext->protocol, 200);
		}
		else {
			rsp = UAXMessageRsp(sip, UContext->uac_code, UContext->uac_domain, UContext->uac_ip, UContext->uac_port,
				UContext->uas_code, UContext->uas_domain, UContext->uas_ip, UContext->uas_port, UContext->CSeq, UContext->protocol, 401);

			UAXEncAuthenticate(rsp, UContext, crypt, enc_type);
		}
	}
	return rsp;
}

void* UASQueryCatalogReq(UAContext* UContext)
{
	char xml_body[512];
	int size = CreateQueryCatalogXml(xml_body, UContext->uac_code, 0);

	void* req = UAXMessageReq(SIP_MT_MESSAGE, UContext->uac_code, UContext->uac_domain, UContext->uac_ip, UContext->uac_port,
		UContext->uas_code, UContext->uas_domain, UContext->uas_ip, UContext->uas_port, UContext->CSeq, UContext->protocol);
	UAXMessageContent(req, MESSAGE_XML, xml_body, size);
	return req;
}